package com.baidu.customview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.baidu.customview.R;
import com.baidu.customview.bean.RobotBean;
import com.baidu.customview.viewholder.AdapterRobotItemHolder;

import java.util.ArrayList;

/**
 * Created by Kvin on 2016/1/7.
 */
public class RobotItemAdapter extends MBaseAdapter<RobotBean> {

    public RobotItemAdapter(final ArrayList<RobotBean> list, final Context context) {
        super(list, context, new BaseAdapterCallback() {
            @Override
            public View getView(int position, View convertView, ViewGroup parent, LayoutInflater inflater) {
                AdapterRobotItemHolder holder;
                if (convertView == null) {
                    convertView = inflater.inflate(R.layout.adapter_robot_item, parent, false);
                    holder = new AdapterRobotItemHolder(convertView);
                    convertView.setTag(holder);
                } else {
                    holder = (AdapterRobotItemHolder) convertView.getTag();
                }
                holder.getIcon().setImageResource(list.get(position).getIcon());
                holder.getName().setText(list.get(position).getName());
                return convertView;
            }
        });
    }
}
